<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="root">
        <!-- $destroy "自杀" 组件中的功能都会被清理掉 但是dom还是会渲染在页面上 -->
        <button @click='$destroy()'>点击卸载组件</button>
        <p v-show='isDest'>11111</p>
    </div>

    <script src="../js/vue.js"></script>
    <script>
        new Vue({
            el: '#root',
            data: {
                count: 0,
                isDest: true
            },
            //定义一个定时器让状态发生变化
            //mounted 是挂载完成时触发
            mounted() {
                //自己定义的方法Vue在挂载是不会帮助我们清理 需要自己手动清理
                this.timer = setTimeout(() => {
                    console.log(222)
                }, 2000)
            },

            //卸载阶段
            beforeDestroy() {
                //手动清理定时器
                // clearInterval(this.timer)
            }
        })
    </script>
</body>

</html>